<template>
   <view>
    
    <UserSearch></UserSearch>
     <!-- 标签模块开始 -->
     <u-tabs :list="list" :is-scroll="false" 
     :current="current" @change="change"
     active-color="#ff2d4a"
     bar-width="150"
     >
    </u-tabs>

    <view v-if="current===0" class="mins">
       
        <navigator v-for="item in goods " :key="item.goods_id" :url="`/pages/good_detial/good_detial?goods_id=${item.goods_id}`">
        <view class="goods-piv">
            <view class="goods_pic">
                    <u-image  :src="item.goods_small_logo" mode="widthFix"  ></u-image>
            </view>
            <view class="goods_info">
                        <view class="goods_infos" u-line-2>
                                {{item.goods_name}}
                        </view>
                            <!-- 商品价格 -->
                        <view class="goods_pice">
                            ￥{{item.goods_price}}
                        </view>
            </view>

        </view>
           
          

    </navigator>
          
    
    </view>
    <view v-if="current===1">
        销量内容
    </view>
    <view v-if="current===2">
        价格内容
    </view>
     <!-- 标签模块结束-->
   </view>
     
</template>
<script>
export default {
		data() {
			return {
				list: [{
					name: '综合'
				}, {
					name: '销量'
				}, {
					name: '价格'
				}],
                current: 0,
                goods:[]
			}
    },
    onLoad(option) {
        // console.log(option);
        // 定义一个全局的变量 用于接收接口的参数
        this.list = {
            query: '',
            cid: 5,
            pagenum: 1,
            pagesize: 10,
        },
            this.getGoods();
       
    },
		methods: {
			change(index) {
				this.current = index;
            },
          async  getGoods() {
              const res = await this.$u.get('/goods/search', this.params);
            //   console.log(res);
              this.goods = [...this.goods,...res.message.goods]
            this.total =res.message.total
            }
    },
    onReachBottom() {
        // console.log("onReachBottom");
        if (this.goods.length < this.total) {
            // 页码++
            this.list.pagenum ++
            this.getGoods()
            // console.log(this.total);
            
        } else {
            uni.showToast({
                title: '没有数据了',
                icon:'none'
            })

        }
    },
   async onPullDownRefresh() {
        // 下拉获取最新数据
        // 将页码改成1
        // 将数据清除
        // 从小调用接口
        this.list.pagenum = 1
        this.list = []
        this.getGoods()
      await  uni.stopPullDownRefresh()
    },


  
   
        
	}
</script>
<style lang="scss" scoped>
.goods-piv{
    display: flex;
    .goods_pic{
        flex:1;
        padding: 15rpx;
        

    }
    .goods_info{
        flex:3;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .goods_infos{

        }
        .goods_pice{
            color:#eb4450;
            font-size: 30rpx;
        }
    }
}
</style>